package com.lwj.springbootvue.controller;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.lwj.springbootvue.model.Teacher;
import com.lwj.springbootvue.response.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lwj.springbootvue.service.ITeacherService;


/**
 * 教师Controller
 * 
 * @author king
 * @date 2024-12-25
 */


@RestController
@RequestMapping("/teacher")
public class TeacherController
{
    @Autowired
    private ITeacherService teacherService;

    /**
     * 查询教师列表
     */
    @GetMapping("/list")
    public Result list(Teacher teacher)
    {
        PageInfo<Teacher> studentVoPageInfo = teacherService.selectTeacherList(teacher);
        List<Teacher> studentVosList = studentVoPageInfo.getList();
        // 添加 total对象，返回前端
        return Result.success(studentVosList).put("total",studentVoPageInfo.getTotal());
    }


    /**
     * 获取教师详细信息
     */
    @GetMapping(value = "/{tid}")
    public Result getInfo(@PathVariable("tid") Long tid)
    {
        return Result.success(teacherService.selectTeacherByTid(tid));
    }

    /**
     * 新增教师
     */
    @PostMapping
    public Result add(@RequestBody Teacher teacher)
    {
        return Result.success(teacherService.insertTeacher(teacher));
    }

    /**
     * 修改教师
     */
    @PutMapping
    public Result edit(@RequestBody Teacher teacher)
    {
        return Result.success(teacherService.updateTeacher(teacher));
    }

    /**
     * 删除教师
     */
	@DeleteMapping("/{tids}")
    public Result remove(@PathVariable Long[] tids)
    {
        return Result.success(teacherService.deleteTeacherByTids(tids));
    }
}
